package cn.ml.sheJiMoShi.single.lanHan;
/*
 * 最简单的懒汉单例模式
 */
public class Lazy {
    private static Lazy lazy;

    private Lazy(){
        System.out.println(Thread.currentThread().getName() + "ok");
    }

    //单线程没问题
    public static Lazy getInstance(){
        if(lazy == null){
            lazy = new Lazy();
        }
        return lazy;
    }

    public static void main(String[] args) {
        for (int i = 0; i < 10; i++){
            new Thread(()->{
                Lazy.getInstance();
            }).start();
        }
    }
}
